
import {Badge, Button, Table} from 'antd';
import {useEffect, useState} from "react";
import axios from "axios";
import EasyName from "./EasyName";

const OrdersTable2 = () => {
    const [dataSource,setDataSource] = useState([])
    const getList =  async () => {
        try {
            const response = await axios.get('http://localhost:8084/order/OfflineList', {
                orderObtain: sessionStorage.getItem('phone')
            });
            console.log(response.data.data.records)
            setDataSource(response.data.data.records)
        } catch (error) {
            console.error(error);
        }
    }
    useEffect(() => {
        getList();
    },[]);
    const columns = [
        {
            title: '订单编号',
            dataIndex: 'orderId',
            key: 'orderId',
            width: '15%',
        },
        {
            title: '下单时间',
            dataIndex: 'orderTime',
            key: 'orderTime',
            width: '15%',
        },
        {
            title: '预约验货时间',
            dataIndex: 'orderAppointment',
            key: 'orderAppointment',
            width: '15%',
            render: (orderAppointment) => (
                <span>{new Date(orderAppointment).toLocaleString()}</span>
            )
        },
        {
            title: '商品名称',
            dataIndex: 'stockId',
            key: 'stockId',
            width: '15%',
            render: (stockId) => (
                <span><EasyName param={stockId}/></span>
            )
        },
        {
            title: '预购数量',
            dataIndex: 'orderAccount',
            key: 'orderAccount',
            width: '10%',
        },
        {
            title: '预付金额',
            dataIndex: 'orderSum',
            key: 'orderSum',
            width: '10%',
        },
        {
            title: '货物状态',
            dataIndex: 'orderConfirm',
            key: 'orderConfirm',
            width: '10%',
            render: (orderConfirm) => {
                return orderConfirm === '未确认' ?
                    (<Badge status="error" text="未收货"/>) :
                    (<Badge status="success" text="已收货"/>);
            },
        },
        {
            title: '操作',
            dataIndex: '',
            key: '',
            render: (record) => (
                <>
                    {record.orderConfirm === '未确认' ?
                        <Button primary >确认收货</Button> :
                        <Button danger>删除订单</Button>
                    }
                </>
            )
        }
    ];

    return <Table columns={columns} dataSource={dataSource} />;
};
export default OrdersTable2;